﻿using System.Collections.Generic;
using Missbot.Common;
using Missbot.Core.Scheduler;

namespace Missbot.AIModule.Schedulers
{
    public abstract class IScheduler : ISingleton
    {
        protected abstract List<ScheduleMeta> ModelList { get; set; }
        public abstract string Owner { get; }

        public virtual bool Enabled => true;

        public SchedulerSvc SchedulerSvc { get; set; }

        public virtual void Work()
        {
            foreach (var model in ModelList)
            {
                SchedulerSvc.Add(model.Span, TimeUp, model.Data, IsImmdiately: model.IsImmediately);
            }
        }

        private void TimeUp(SchedulerTimer timer)
        {
            ScheduleDo(timer);
        }

        protected abstract void ScheduleDo(SchedulerTimer timer);
    }

    public class ScheduleMeta
    {
        public IScheduleSpan Span { get; init; }

        public bool IsImmediately { get; init; }

        public object Data { get; set; }
    }
}